package com.edu.exam.entity.classmanagement.administrative;

import com.edu.exam.enums.OperationType;
import com.edu.exam.enums.common.OperationResult;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 行政班级操作日志实体类
 * 所属模块：F-05 行政班级管理模块
 * 对应数据库表：administrative_operation_log
 *
 * 记录行政班级管理相关的所有操作日志，包括班级创建、修改、删除、
 * 学生分班、班级调整等操作的详细记录。支持操作追踪、审计和统计分析。
 * 记录操作人、操作时间、操作类型、操作结果等关键信息。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class AdministrativeOperationLog {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull(message = "操作类型不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "operation_type", nullable = false, length = 30)
    private OperationType operationType;

    @Column(name = "class_id")
    private Long classId;

    @Size(max = 50, message = "学生ID长度不能超过50个字符")
    @Column(name = "student_id", length = 50)
    private String studentId;

    @NotNull(message = "操作人ID不能为空")
    @Column(name = "operator_id", nullable = false)
    private Long operatorId;

    @NotBlank(message = "操作人姓名不能为空")
    @Size(max = 100, message = "操作人姓名长度不能超过100个字符")
    @Column(name = "operator_name", nullable = false, length = 100)
    private String operatorName;

    @NotNull(message = "操作时间不能为空")
    @CreatedDate
    @Column(name = "operation_time", nullable = false, updatable = false)
    private LocalDateTime operationTime;

    @Size(max = 100, message = "客户端IP地址长度不能超过100个字符")
    @Column(name = "client_ip_address", length = 100)
    private String clientIpAddress;

    @Size(max = 500, message = "操作描述长度不能超过500个字符")
    @Column(name = "operation_description", length = 500)
    private String operationDescription;

    @Size(max = 2000, message = "操作详情长度不能超过2000字符")
    @Column(name = "operation_details", columnDefinition = "TEXT")
    private String operationDetails;

    @NotNull(message = "操作结果不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "operation_result", nullable = false, length = 20)
    @Builder.Default
    private OperationResult operationResult = OperationResult.SUCCESS;

    @Size(max = 500, message = "失败原因长度不能超过500个字符")
    @Column(name = "failure_reason", length = 500)
    private String failureReason;

    @Size(max = 100, message = "批量操作ID长度不能超过100个字符")
    @Column(name = "batch_operation_id", length = 100)
    private String batchOperationId;

    @Size(max = 1000, message = "备注信息长度不能超过1000字符")
    @Column(name = "remarks", length = 1000)
    private String remarks;

    @Column(name = "deleted", nullable = false)
    @Builder.Default
    private Boolean deleted = false;


}
